{

  //声明函数
  function add(a: number, b: number): number{
    return a + b;
  }

  //匿名函数
  let sub = function(a: number, b: number): number{
    return a - b;
  }

  //箭头函数
  let divide = (a: number, b: number): number => {
    return a / b;
  }

  //返回值类型可以省略
  let times = (a:number, b: number) => {
    return a * b;
  }

  //函数类型的变量声明
  // let pow: (a: number, b: number) => number; 
  // pow = (a, b) => {
  //   return a**b;
  // }

  let pow: (a: number, b: number) => number = (a, b)=>{
    return a ** b;
  }

  //可选参数的设置  'abc'.slice(1)  'abc'.slice(1, 6)
  function slice(str: string, start: number, end ?: number){
  }

  slice('xxx', 2, 5);
  slice('xxx', 1);

  //剩余参数
  function sum(...args: Array<number>){
    console.log(args);
  }

  sum(1,2,3);
  sum(1,2,3,4,5,6,6);
  sum(1,2,3,4,51,12,12,3,44,4,19);

  //函数参数的默认值
  function buildPhone(code:string, area:string="+86"){
    return area + code;
  }

  buildPhone('13898743569', '+86');
  buildPhone('13898743569', '+123');
  buildPhone('13898743569');

}